import React from "react";
import {
  HashRouter as Router,
  Switch,
  Route,
} from "react-router-dom";
import Info from "../views/info";
import Reg from "../views/admins/reg"
import { isLogin } from "../util/users";
import { lazy } from "../util";
import { Redirect } from "react-router";
const Login = lazy("views/admins/login")


function AuthSet({ path, commponent, to = "/" }) {
  const Commponent = commponent;
  return <Route
    path={path}
    render={props => {
      const status = isLogin();
      if (status) {
        return <Commponent />
      };
      return <Redirect to={to} />
    }} />
}

//eslint-disable-next-line
export default () => {
  return (
    <Router>
      <div>
        {/* A <Switch> looks through its children <Route>s and
            renders the first one that matches the current URL. */}
        <Switch >
          <AuthSet path="/info" commponent={Info} to="/" />
          <Route path="/reg">
            <Reg />
          </Route>
          <Route exact path="/">
            <Login />
          </Route>
          <Route path="/login/:adminName">
            <Login />
          </Route>


        </Switch>
      </div>
    </Router>
  )
}